package cn.yusei.teamTribe.dao.team;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import cn.yusei.teamTribe.dao.team.po.TeamMemberPO;

@Mapper
public interface TeamMemberDAO {

	final String TEAM_USER_TABLE = " r_user_team ";
	final String INSERT_FIELDS = " (user_id, team_id) ";
	
	@Select({"select exists (select * from", TEAM_USER_TABLE, "where user_id = #{userId} and team_id = #{teamId})"})
	boolean exists(TeamMemberPO tmPO);
	
	@Insert({"insert into", TEAM_USER_TABLE, INSERT_FIELDS, "values (#{userId}, #{teamId})"})
	void insert(TeamMemberPO tmPO);
	
	@Delete({"delete from", TEAM_USER_TABLE, "where user_id = #{userId} and team_id = #{teamId}"})
	void delete(TeamMemberPO tmPO);
	
	@Select({"select user_id from", TEAM_USER_TABLE, "where team_id = #{id} limit #{offset}, #{num}"})
	int[] selectByTeam(@Param("id") int id, @Param("offset") int offset, @Param("num") int num);
	
}
